package interpreter

import (
	"fmt"
	"learning/gooop/behavioral_patterns/interpreter/tokens"
)

type tLogicExpression struct {
	op tokens.Tokens
	left IBoolExpression
	right IBoolExpression
}


func newLogicNode(op tokens.Tokens, left IBoolExpression, right IBoolExpression) *tLogicExpression {
	return &tLogicExpression{
		op, left, right,
	}
}


func (me *tLogicExpression) Eval(row IDataRow) bool {
	switch me.op {
	case tokens.And:
		return me.left.Eval(row) && me.right.Eval(row)

	case tokens.OR:
		return me.left.Eval(row) || me.right.Eval(row)

	default:
		panic(fmt.Sprintf("unsupported bool operation: %s", me.op))
	}
}
